package principe.segregation.improve;


/**
 * 类A 依赖了 B的 1，2，3 方法，
 * 类C 依赖了 D的 1，4，5 方法；
 */
public class Segregation2 {
    public static void main(String[] args) {
        A a = new A();
        a.depend1(new B());
        a.depend2(new B());
        a.depend3(new B());
        C c = new C();
        c.depend1(new D());
        c.depend4(new D());
        c.depend5(new D());
    }
}

//类A
class A {
    public void depend1(Interface1 interface1) {
        interface1.operator1();
    }

    public void depend2(Interface2 interface1) {
        interface1.operator2();
    }

    public void depend3(Interface2 interface1) {
        interface1.operator3();
    }
}

//类C
class C {
    public void depend1(Interface1 interface1) {
        interface1.operator1();
    }

    public void depend4(Interface3 interface1) {
        interface1.operator4();
    }

    public void depend5(Interface3 interface1) {
        interface1.operator5();
    }
}

//接口1中定义了方法1
interface Interface1 {
    void operator1();
}

//接口2中定义了方法2，3
interface Interface2 {
    void operator2();

    void operator3();
}

//接口3中定义了方法4，5
interface Interface3 {
    void operator4();

    void operator5();
}

//类B需要实现接口1，2
class B implements Interface1, Interface2 {

    @Override
    public void operator1() {
        System.out.println("B" + "实现了operator1");
    }

    @Override
    public void operator2() {
        System.out.println("B" + "实现了operator2");
    }

    @Override
    public void operator3() {
        System.out.println("B" + "实现了operator3");
    }
}

//类D中实现了接口1，3
class D implements Interface1, Interface3 {

    @Override
    public void operator1() {
        System.out.println("D" + "实现了operator1");
    }

    @Override
    public void operator4() {
        System.out.println("D" + "实现了operator4");
    }

    @Override
    public void operator5() {
        System.out.println("D" + "实现了operator5");
    }
}